﻿Imports System.Math

Imports OpenTK.Graphics.OpenGL
Public Module ViewerData
    Public piRad As Double = PI / 180
    Public rand As New Random
    Public lockAxes As Axis = Axis.BOTH
    Public workingDir As String = ""
    Public Enum Axis
        NONE = -1
        X = 0
        Y = 1
        BOTH = 2
    End Enum
    Public Structure KeyStatus
        Dim change As Boolean
        Dim W As Boolean
        Dim S As Boolean
        Dim A As Boolean
        Dim D As Boolean
    End Structure
    Public Structure MouseStatus
        Dim change As Boolean
        Dim msLeft As Boolean
        Dim msRight As Boolean
        Dim oldPos As Point
        Dim newPos As Point
        Dim diff As Point
    End Structure
    Public Enum MOVE
        UP = 1
        DOWN = 2
        LEFT = 3
        RIGHT = 4
        NONE = 0
    End Enum
    
    Public Structure PointXYZ
        Dim x As Double
        Dim y As Double
        Dim z As Double
    End Structure
    Public Function Read32(ByVal b() As Byte, ByVal off As Integer) As Int32
        Read32 = b(off) >> 24 + _
            b(off + 1) >> 16 + _
            b(off + 2) >> 8 + _
            b(off + 3)
        Return Read32
    End Function
    Public Function Read16(ByVal b() As Byte, ByVal off As Integer) As Integer
        Read16 = (b(off) << 8) Or b(off + 1)
        Return Read16
    End Function
    Public Function ByteArrayToInteger(ByRef ByteArray() As Byte, ByRef StartIndex As Integer, ByRef EndIndex As Integer) As Integer
        Dim bSubArray(0 To EndIndex - StartIndex) As Byte
        For i As Integer = StartIndex To EndIndex
            bSubArray(i - StartIndex) = ByteArray(i)
        Next
        Return BitConverter.ToInt32(bSubArray, 0)
    End Function
    Public Function GetDir(ByVal fn As String) As String
        For i As Integer = fn.Length - 1 To 0 Step -1
            If fn(i) = "\" Or fn(i) = "/" Then
                Return Mid(fn, 1, i)
            End If
        Next
        Return ""
    End Function
  
    Public Function fromColorToARGB(ByVal col As Color) As Double()
        Dim n As Double() = New Double() {1, 1, 1, 1}
        With col
            n(0) = .A / 255.0F
            n(1) = .R / 255.0F
            n(2) = .G / 255.0F
            n(3) = .B / 255.0F
        End With
        Return n
    End Function
    Public Function FileToBytes(ByVal fn As String) As Byte()
        Dim sr1 As New IO.FileStream(fn, IO.FileMode.Open)
        Dim tB(sr1.length - 1) As Byte
        sr1.Read(tB, 0, sr1.Length - 1)
        sr1.Dispose()
        GC.Collect()
        Return tB
    End Function
End Module
